package com.qt.thread.homework.work2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.stream.Collectors;


/**
 * @Author zsf
 * @Date 2023/10/4 1:02
 * @Version 1.0
 */
public class Demo02 {

    /**
     * 间练习多线程练习5(抽奖箱抽奖)
     * 有一个抽奖池,该抽奖池中存放了奖励的金额,该抽奖池中的奖项为{10,5,20,50,100,200,500,800,2,80,300,700};
     * 创建两个抽奖箱(线程)设置线程名称分别为“抽奖箱1”，“抽奖箱2”随机从抽奖池中获取奖项元素并打印在控制台上.格式如下:
     * 每次抽出一个奖项就打印一个(随机)
     * 抽奖箱1又产生了一个10元天奖
     * 抽奖箱1又产生了一个100元大奖
     * 抽奖箱1又产生了一个200元大奖
     * 抽奖箱1又产生了一个800元大奖
     * 抽奖箱2又产生了一个700元大奖
     */

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        Integer[] arr = {10,5,20,50,100,200,500,800,2,80,300,700};
        //装箱
        List<Integer> integers = Arrays.stream(arr).collect(Collectors.toList());

        CjxCallAble cjx1 = new CjxCallAble(integers);
        CjxCallAble cjx2 = new CjxCallAble(integers);
        CjxCallAble cjx3 = new CjxCallAble(integers);

        FutureTask<Integer> ft1 = new FutureTask<>(cjx1);
        FutureTask<Integer> ft2 = new FutureTask<>(cjx2);
        FutureTask<Integer> ft3 = new FutureTask<>(cjx3);

        Thread t1 = new Thread(ft1, "抽奖箱1");
        Thread t2 = new Thread(ft2,"抽奖箱2");
        Thread t3 = new Thread(ft3,"抽奖箱3");
        t1.start();
        t2.start();
        t3.start();

        System.out.println(t1.getName() + ":" + ft1.get());
        System.out.println(t2.getName() + ":" + ft2.get());
        System.out.println(t3.getName() + ":" + ft3.get());

        ArrayList<Integer> res = new ArrayList<>();
        Collections.addAll(res,ft1.get(),ft2.get(),ft3.get());
        System.out.println("最大奖：" + Collections.max(res));


    }

}
